package sctu.edu.java.year2016.team08.lisonghong.day20160616.chapter12_3;


import java.io.*;
import java.util.Scanner;

/**
 * Created by 松红 on 2016/6/16.
 * 实现当用户输入姓名和密码时，将每一个姓名和密码加在文件中。
 */
public class Login {
    public static void main(String[] args) {
        File file = new File("D:/word.txt");
        for (int i=0;i<10;i++) {
            if (file.exists()) {
                try {
                    FileOutputStream fs = new FileOutputStream("D:/word.txt");
                    DataOutputStream ds = new DataOutputStream(fs);
                    Scanner input = new Scanner(System.in);
                    System.out.println("please enter your uesrname:");
                    String username = input.nextLine();
                    System.out.println("please enter your password:");
                    String password = input.nextLine();
                    ds.writeBytes(username + '\t');
                    ds.writeChars(password);
                    ds.close();
                    FileInputStream fls = new FileInputStream("D:/word.txt");
                    DataInputStream dis = new DataInputStream(fls);
                    System.out.println("\t" + "username" + " " + "password");
                    System.out.println("\t" + dis.readLine());
                    dis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            } else {
                try {
                    file.createNewFile();
                    System.out.println("ok!created");
                } catch (Exception e) {
                    e.printStackTrace();

                }
            }
        }
    }
}
